package cn.qqy.auth.interceptor;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;


@Component
public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        String token = request.getHeader("TOKEN");//获取TOKEN 判断是否登录

        if (token == null){

            //{"success":false,"msg":"noLogin"}
            response.setContentType("application/json;charset=utf-8");
            PrintWriter writer = response.getWriter();
            writer.print("{\"success\":false,\"msg\":\"noLogin\"}");

            return false;
        }

      return true;
    }
}
